package com.lh.eemsserver.Mapper;

import com.lh.eemsserver.po.*;

import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

@Mapper
public interface WorkerMapper {

    @Update("update eemsdb.user set userName=#{userName}, password=#{password} where userID=#{userID}")
    public Integer updateWorker(User user);
    @Select("select * from eemsdb.user where userID=#{userID} and role=#{role}")
    public User getUserById(User user);
    @Select("select * from eemsdb.user where userID=#{userID} and password=#{password} and role=#{role}")
    public User userlogin(User user);
    @Select("select distinct *  from eemsdb.report,eemsdb.event,eemsdb.reporter,eemsdb.riskenterprise where report.reporterPhone=reporter.reporterPhone and report.enterpriseID=riskenterprise.enterpriseID and report.eventID=event.eventID")
    public List<Report> listAllReport();
    @Select("select distinct *  from eemsdb.report,eemsdb.event,eemsdb.reporter,eemsdb.riskenterprise where report.reporterPhone=reporter.reporterPhone and report.enterpriseID=riskenterprise.enterpriseID and report.eventID=event.eventID and reporter like CONCAT('%', #{reporter}, '%')")
    public List<Report> listReportByReporter(Report report);
    @Select("select distinct *  from eemsdb.report,eemsdb.event,eemsdb.reporter,eemsdb.riskenterprise where report.reporterPhone=reporter.reporterPhone and report.enterpriseID=riskenterprise.enterpriseID and report.eventID=event.eventID and reportState like CONCAT('%', #{reportState}, '%')")
    public List<Report> listReportByState(Report report);
    @Select("select distinct *  from eemsdb.report,eemsdb.event,eemsdb.reporter,eemsdb.riskenterprise where report.reporterPhone=reporter.reporterPhone and report.enterpriseID=riskenterprise.enterpriseID and report.eventID=event.eventID and reportID like CONCAT('%', #{reportID}, '%')")
    public List<Report> listReportByReportID(Report report);
    @Select("select distinct *  from eemsdb.report,eemsdb.event,eemsdb.reporter,eemsdb.riskenterprise where report.reporterPhone=reporter.reporterPhone and report.enterpriseID=riskenterprise.enterpriseID and report.eventID=event.eventID and lastUpdater like CONCAT('%', #{lastUpdater}, '%')")
    public List<Report> listReportByLastUpdater(Report report);
    @Select("select distinct eventType from eventType")
    public String[] listAllEventType();

    @Select("select count(*) as reportNum from eemsdb.reporter where reporterPhone=#{reporterPhone}")
    public int getReporter(Report report);

    @Select("select count(*) as checkerNum from eemsdb.checker where checkerPhone=#{checkerPhone}")
    public int getCheckerNum(Material material);
    //主页显示所有接报处理状态信息
    @Insert("insert into eemsdb.report(reportName, reporterPhone, reportTime, enterpriseID, lastUpdater, lastUpdateTime, reportState, eventID, remark) values(#{reportName},#{reporterPhone},#{reportTime},#{enterpriseID},#{lastUpdater},#{lastUpdateTime},#{reportState},#{eventID},#{remark})")
    public int newReportInfo(Report report);
    @Insert("insert into eemsdb.reporter(reporterPhone, reporter) VALUES(#{reporterPhone},#{reporter})")
    public int newReporterInfo( Report report);
    //创建接报页面
    @Select("select cityName from city")
    public String[] listAllCityName();

    @Select("select materialLocation from materialLocation")
    public String[] listAllLocationName();



    //默认情况下无查询内容时显示所有城市信息
    public List<City> listSelectedCity(String cityName);
    //用户输入查询字段后进行查询的城市信息

    @Update("update city set  cityName=#{cityName},rescuePersonnel=#{rescuePersonnel},rescueVehicles=#{rescueVehicles},trafficCondition=#{trafficCondition} where cityID=#{cityID}")
    public int renewCityInfo(City city);
    //城市的用资信息可以进行修改



    @Select("select * from eemsdb.`procedure` where eventType=#{eventType} order by steps ")
    public List<Procedure> getProcedure(Report report);
    @Update("update eemsdb.`procedure` set steps=steps+1 where steps>=#{steps} and eventType=#{eventType}")
    public int addProcedureStep(Procedure procedure);
    @Insert("insert into eemsdb.`procedure`(procedureName,eventType,steps,content) values(#{procedureName},#{eventType},#{steps},#{content})")
    public int insertProcedureStep(Procedure procedure);
    @Update("update eemsdb.`procedure` set procedureName=#{procedureName} ,content=#{content} where procedureID=#{procedureID}")
    public int renewProcedureStep(Procedure procedure);
    @Update("update eemsdb.`procedure` set steps=steps-1 where steps>=#{steps} and eventType=#{eventType}")
    public int downProcedureStep(Procedure procedure);
    @Delete("delete from eemsdb.`procedure` where steps=#{steps}-1 and eventType=#{eventType}")
    public int delProcedureStep(Procedure procedure);
    @Select("select * from eemsdb.`procedure` where procedureID=#{procedureID}")
    public Procedure getProcedureByID(Procedure procedure);

    @Insert("insert into eemsdb.eventtype values(#{eventType})")
    public int newEventType(Event event);


    //通过流程类型获取流程信息
    public int newProcedureInfo(Procedure procedure);
    //为一个新类型的事件创建流程 不是添加流程步骤！！！
    //为其设置成响应式数组对象实现表格型数据双向绑定 将修改后的数据最终提交给后端
    //let report = ref([{
    //    reportName:"",
    //    reportContent:""
    //}])
    //点击添加流程步骤后端并没有做任何事 只是为了好看
    public int delProcedureInfo(Procedure procedure);
    //删除流程信息
    @Select("select distinct * from eemsdb.material,eemsdb.checker,eemsdb.materiallocation,eemsdb.city where eemsdb.material.locationName=eemsdb.materiallocation.materialLocation and eemsdb.material.checkerPhone = eemsdb.checker.checkerPhone and eemsdb.materialLocation.cityID=eemsdb.city.cityID")
    public List<Material> ListAllMaterialInfo();
    //列出所有物资以及位置相关信息  这里我将物资信息与位置写在了一个表里
    @Select("select distinct * from eemsdb.material,eemsdb.checker,eemsdb.materiallocation,eemsdb.city where eemsdb.material.locationName=eemsdb.materiallocation.materialLocation and eemsdb.material.checkerPhone = eemsdb.checker.checkerPhone and eemsdb.materialLocation.cityID=eemsdb.city.cityID and locationName like CONCAT('%', #{locationName}, '%')")
    public List<Material> ListMaterialByLocation(Material material);
    @Select("select distinct * from eemsdb.material,eemsdb.checker,eemsdb.materiallocation,eemsdb.city where eemsdb.material.locationName=eemsdb.materiallocation.materialLocation and eemsdb.material.checkerPhone = eemsdb.checker.checkerPhone and eemsdb.materialLocation.cityID=eemsdb.city.cityID and materialName like CONCAT('%', #{materialName}, '%')")
    public List<Material> getMaterialInfoByName(Material material);

//    @Insert("insert into eemsdb.materialLocation values(#{locationName},(select cityID from eemsdb.city where cityName=#{cityName}))")
//    public int insertMaterialLocation(Material material);
    @Insert("insert into eemsdb.checker(checkerPhone, checkTime, checker) values(#{checkerPhone},#{checkTime},#{checker});")
    public int insertChecker(Material material);
    @Insert("insert into eemsdb.material(materialName,checkerPhone,locationName,materialNum) values(#{materialName},#{checkerPhone},#{locationName},#{materialNum});")
    public int insertMaterial(Material material);


//    @Update("update eemsdb.materiallocation set cityID=(select cityID from city where cityName = #{cityName}) where materialLocation = #{materialLocation}")
//    public int renewMaterialLocation(Material material);

    @Update("update eemsdb.checker set checker=#{checker},checkTime=#{checkTime} where checkerPhone = #{checkerPhone}")
    public int renewChecker(Material material);

    @Update("update eemsdb.material set materialName=#{materialName},materialNum=#{materialNum},locationName=#{locationName} where materialID=#{materialID}")
    public int renewMaterial(Material material);

    @Select("select * from eemsdb.city")
    public List<City> listAllCity(City city);
    @Select("select * from eemsdb.city where cityName like CONCAT('%', #{cityName}, '%')")
    public List<City> listCityByName(City city);




    public int delMaterialInfo(Material material);

    public int delAllMaterialInfo();

    @Select("select * from eemsdb.riskenterprise,eemsdb.legalPerson where riskenterprise.legalpersonphone=legalPerson.legalpersonphone")
    public List<Enterprise> listAllEnterpriseInfo(Enterprise enterprise);
    @Select("select * from eemsdb.riskenterprise,eemsdb.legalPerson where riskenterprise.legalpersonphone=legalPerson.legalpersonphone and enterpriseName like CONCAT('%', #{enterpriseName}, '%')")
    public List<Enterprise> listEnterpriseInfoByName(Enterprise enterprise);
    @Select("select * from eemsdb.riskenterprise,eemsdb.legalPerson where riskenterprise.legalpersonphone=legalPerson.legalpersonphone and enterpriseType like CONCAT('%', #{enterpriseType}, '%')")
    public List<Enterprise> listEnterpriseInfoByType(Enterprise enterprise);

    @Insert("insert into eemsdb.riskenterprise(enterpriseName,address,legalpersonphone,latitude,longitude,enterpriseType) values(#{enterpriseName},#{address},#{legalpersonphone},#{latitude},#{longitude},#{enterpriseType})")
    public int newEnterpriseInfo(Enterprise enterprise);
    @Insert("insert into eemsdb.legalperson(legalpersonphone,legalPerson) values(#{legalpersonphone},#{legalPerson})")
    public int newLegalPersonInfo(Enterprise enterprise);


    public int renewEnterpriseInfo(Enterprise enterprise);

    public int delEnterpriseInfo(Enterprise enterprise);

    public int delAllEnterpriseInfo();

    @Select("select * from eemsdb.event order by eventLevel")
    public List<Event> listAllEventInfo();
    @Select("select * from eemsdb.event where eventName like CONCAT('%', #{eventName}, '%')")
    public List<Event> listEventInfoByName(Event event);
    @Select("select * from eemsdb.event where eventLevel like CONCAT('%', #{eventLevel}, '%')")
    public List<Event> listEventInfoByRank(Event event);
    @Select("select * from eemsdb.event where eventType like CONCAT('%', #{eventType}, '%')")
    public List<Event> listEventInfoByType(Event event);
    @Select("select * from eemsdb.event where eventID=#{eventID}")
    public Event getEventInfoByID(Event event);
    @Update("update eemsdb.event set eventName=#{eventName}, eventLevel=#{eventLevel},eventType=#{eventType},remarks=#{remarks} where eventID=#{eventID}")
    public int renewEventInfo(Event event);
    @Select("select * from eemsdb.city where  cityID=#{cityID}")
    public City getCityByID(City city);

    @Insert("insert into eemsdb.event(remarks,eventName,eventType,eventLevel) values (#{remarks},#{eventName},#{eventType},#{eventLevel});")
    public int newEventInfo(Event event);
    @Delete("delete from eemsdb.event where eventID=#{eventID}")
    public int delEventInfo(Event event);

    public int delAllEventInfo();

    public String getEventId(Event event);


    @Select("select * from eemsdb.user where userID=#{userID} and password=#{password}")
    public User getUserName(User user);
    //既适用于登录又适用于登陆成功后界面右上角信息展示
}
